﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Hallenberg.Core;
using System.Web.Mvc;

namespace Hallenberg.SmartClient.MVC
{
    public static class ValidationExceptionExtensions
    {
        public static void ApplyToModelState(this ValidationException validationException, ModelStateDictionary modelState)
        {
            foreach (string field in validationException.ValidationErrors.Keys)
            {
                foreach (string errorMessage in validationException.ValidationErrors[field])
                {
                    modelState.AddModelError(field, errorMessage);
                }
            }
        }
    }
}
